package com.zyylr.classroomreservationsystem.bean;

import android.content.Context;
import android.content.Intent;

import com.zyylr.classroomreservationsystem.consts.GlobalConsts;

import java.util.Date;

/**
 * 已登录的用户，单例模式
 * 用户登录成功后将实例化一个对象，否则为空
 */
public class LoginUser extends User {
    private static LoginUser instance = null;

    private LoginUser(String username, String password, String name, Date admission_date, Integer role) {
        super(username, password, name, admission_date, role);
    }

    /**
     * 登录，生成登录实例对象
     *
     * @param user 传进的user对象
     */
    public static void login(User user) {
        instance = new LoginUser(user.getUsername(), user.getPassword(), user.getName(), user.getAdmission_date(), user.getRole());
    }

    /**
     * 退出登录，销毁对象
     */
    public static void logout() {
        instance = null;
    }

    /**
     * 返回当前登录状态
     *
     * @return true登录，false未登录
     */
    public static boolean isLogin() {
        return instance != null;
    }

    public static LoginUser getInstance() {
        return instance;
    }
}
